/*     */ package me.wazup.kitbattle;
/*     */ 
/*     */ import java.sql.ResultSet;
/*     */ import java.sql.SQLException;
/*     */ import java.sql.Statement;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Collection;
/*     */ import java.util.List;
/*     */ import org.bukkit.Bukkit;
/*     */ import org.bukkit.ChatColor;
/*     */ import org.bukkit.GameMode;
/*     */ import org.bukkit.Location;
/*     */ import org.bukkit.Material;
/*     */ import org.bukkit.configuration.file.FileConfiguration;
/*     */ import org.bukkit.entity.Player;
/*     */ import org.bukkit.inventory.Inventory;
/*     */ import org.bukkit.inventory.InventoryHolder;
/*     */ import org.bukkit.inventory.ItemStack;
/*     */ import org.bukkit.plugin.Plugin;
/*     */ import org.bukkit.potion.PotionEffect;
/*     */ import org.bukkit.scheduler.BukkitRunnable;
/*     */ 
/*     */ 
/*     */ 
/*     */ public class PlayerData
/*     */ {
/*     */   boolean joined = false;
/*     */   private ItemStack[] items;
/*     */   private ItemStack[] armor;
/*     */   private Location location;
/*     */   private double health;
/*     */   private int food;
/*     */   private int levels;
/*     */   private float exp;
/*     */   private Collection<PotionEffect> potions;
/*     */   private GameMode mode;
/*     */   private boolean flying;
/*     */   private main plugin;
/*     */   private String map;
/*     */   private Kit kit;
/*     */   Inventory myKits;
/*     */   Inventory Shop;
/*  43 */   long cooldown = 0L;
/*  44 */   int killstreak = 0;
/*     */   
/*  46 */   int kills = 0;
/*  47 */   int deaths = 0;
/*  48 */   int coins = 0;
/*  49 */   int dataexp = 0;
/*     */   Rank rank;
/*  51 */   int rankNumber = 0;
/*     */   Rank nextRank;
/*  53 */   int kitUnlockers = 0;
/*     */   
/*     */   public PlayerData(Player p, main plugin) {
/*  56 */     this.plugin = plugin;
/*  57 */     loadStats(p);
/*     */   }
/*     */   
/*     */   public void loadStats(final Player p) {
/*  61 */     final String playerName = this.plugin.target(p);
/*  62 */     (new BukkitRunnable() {
/*     */         public void run() {
/*  64 */           PlayerData.this.myKits = Bukkit.createInventory((InventoryHolder)p, 54, ChatColor.RED + ChatColor.UNDERLINE + ChatColor.UNDERLINE + "My kits");
/*  65 */           List<String> ownedKits = new ArrayList<String>();
/*  66 */           if (PlayerData.this.plugin.config.useMySQL) {
/*     */             
/*  68 */             if (PlayerData.this.plugin.connection == null) {
/*  69 */               (new BukkitRunnable() {
/*     */                   public void run() {
/*  71 */                     p.kickPlayer(String.valueOf((PlayerData.null.access$0(PlayerData.null.this)).plugin.kb) + (PlayerData.null.access$0(PlayerData.null.this)).plugin.msgs.LoadStatsFailureMySql);
/*     */                   }
/*  73 */                 }).runTask((Plugin)PlayerData.this.plugin);
/*     */               return;
/*     */             } 
/*     */             try {
/*  77 */               Statement sql = PlayerData.this.plugin.connection.createStatement();
/*  78 */               String prefix = PlayerData.this.plugin.config.tableprefix;
/*  79 */               if (sql.executeQuery("SELECT * FROM " + prefix + " WHERE " + PlayerData.this.plugin.playerNamePrefix + " = '" + playerName + "';").next()) {
/*  80 */                 ResultSet generalData = sql.executeQuery("SELECT Coins FROM " + prefix + " WHERE " + PlayerData.this.plugin.playerNamePrefix + " = '" + playerName + "';");
/*  81 */                 generalData.next();
/*  82 */                 PlayerData.this.coins = generalData.getInt("Coins");
/*  83 */                 generalData = sql.executeQuery("SELECT Kills FROM " + prefix + " WHERE " + PlayerData.this.plugin.playerNamePrefix + " = '" + playerName + "';");
/*  84 */                 generalData.next();
/*  85 */                 PlayerData.this.kills = generalData.getInt("Kills");
/*  86 */                 generalData = sql.executeQuery("SELECT Deaths FROM " + prefix + " WHERE " + PlayerData.this.plugin.playerNamePrefix + " = '" + playerName + "';");
/*  87 */                 generalData.next();
/*  88 */                 PlayerData.this.deaths = generalData.getInt("Deaths");
/*  89 */                 generalData = sql.executeQuery("SELECT Kitunlockers FROM " + prefix + " WHERE " + PlayerData.this.plugin.playerNamePrefix + " = '" + playerName + "';");
/*  90 */                 generalData.next();
/*  91 */                 PlayerData.this.kitUnlockers = generalData.getInt("Kitunlockers");
/*  92 */                 generalData = sql.executeQuery("SELECT Exp FROM " + prefix + " WHERE " + PlayerData.this.plugin.playerNamePrefix + " = '" + playerName + "';");
/*  93 */                 generalData.next();
/*  94 */                 PlayerData.this.dataexp = generalData.getInt("Exp");
/*  95 */                 generalData = sql.executeQuery("SELECT Rank FROM " + prefix + " WHERE " + PlayerData.this.plugin.playerNamePrefix + " = '" + playerName + "';");
/*  96 */                 generalData.next();
/*  97 */                 PlayerData.this.rank = PlayerData.this.plugin.Ranks.get(generalData.getString("Rank").toLowerCase());
/*  98 */                 generalData = sql.executeQuery("SELECT Kits FROM " + prefix + " WHERE " + PlayerData.this.plugin.playerNamePrefix + " = '" + playerName + "';");
/*  99 */                 generalData.next();
/* 100 */                 String[] spliter = generalData.getString("Kits").split(", ");
/* 101 */                 for (int i = 0; i < spliter.length; i++) {
/* 102 */                   ownedKits.add(spliter[i].toLowerCase());
/*     */                 }
/* 104 */                 sql.close();
/* 105 */                 generalData.close();
/*     */               } else {
/* 107 */                 PlayerData.this.giveDefaultStats(ownedKits);
/*     */               } 
/* 109 */             } catch (SQLException e) {
/* 110 */               e.printStackTrace();
/*     */             } 
/*     */           } else {
/*     */             
/* 114 */             FileConfiguration file = PlayerData.this.plugin.fileManager.getPlayersConfig();
/* 115 */             if (file.contains("Players." + playerName)) {
/* 116 */               PlayerData.this.coins = file.getInt("Players." + playerName + ".Coins");
/* 117 */               PlayerData.this.kills = file.getInt("Players." + playerName + ".Kills");
/* 118 */               PlayerData.this.deaths = file.getInt("Players." + playerName + ".Deaths");
/* 119 */               PlayerData.this.kitUnlockers = file.getInt("Players." + playerName + ".Kit-Unlockers");
/* 120 */               PlayerData.this.dataexp = file.getInt("Players." + playerName + ".Exp");
/* 121 */               PlayerData.this.rank = PlayerData.this.plugin.Ranks.get(file.getString("Players." + playerName + ".Rank").toLowerCase());
/* 122 */               for (String x : file.getStringList("Players." + playerName + ".Kits")) {
/* 123 */                 ownedKits.add(x.toLowerCase());
/*     */               }
/*     */             } else {
/* 126 */               PlayerData.this.giveDefaultStats(ownedKits);
/*     */             } 
/*     */           } 
/*     */           
/* 130 */           PlayerData.this.updateRankNumber();
/* 131 */           PlayerData.this.updateNextRank();
/* 132 */           for (String kitss : ownedKits) {
/* 133 */             if (PlayerData.this.plugin.Kits.containsKey(kitss)) {
/* 134 */               PlayerData.this.myKits.addItem(new ItemStack[] { ((Kit)(PlayerData.access$0(this.this$0)).Kits.get(kitss)).getLogo() });
/*     */             }
/*     */           } 
/*     */           
/* 138 */           PlayerData.this.Shop = Bukkit.createInventory((InventoryHolder)p, 54, ChatColor.RED + ChatColor.UNDERLINE + ChatColor.UNDERLINE + "Purchase more kits!");
/* 139 */           for (String kitName : PlayerData.this.plugin.Kits.keySet()) {
/* 140 */             if (!ownedKits.contains(kitName)) {
/* 141 */               PlayerData.this.Shop.addItem(new ItemStack[] { ((Kit)(PlayerData.access$0(this.this$0)).Kits.get(kitName)).getShopLogo() });
/*     */             }
/*     */           } 
/*     */         }
/* 145 */       }).runTaskLaterAsynchronously((Plugin)this.plugin, 2L);
/*     */   }
/*     */   
/*     */   public void saveStatsIntoFile(final Player p, boolean disabled) {
/* 149 */     if (!this.joined)
/* 150 */       return;  if (!disabled) {
/* 151 */       (new BukkitRunnable() {
/*     */           public void run() {
/* 153 */             if (PlayerData.this.plugin.config.useMySQL) {
/* 154 */               PlayerData.this.saveStatsInMySQL(p);
/*     */             } else {
/* 156 */               PlayerData.this.saveStatsInPlayersFile(p);
/*     */             } 
/*     */           }
/* 159 */         }).runTaskAsynchronously((Plugin)this.plugin);
/*     */     }
/* 161 */     else if (this.plugin.config.useMySQL) {
/* 162 */       saveStatsInMySQL(p);
/*     */     } else {
/* 164 */       saveStatsInPlayersFile(p);
/*     */     } 
/*     */   }
/*     */   
/*     */   public void saveStatsInMySQL(Player p) {
/*     */     String Kits;
/* 170 */     if (this.plugin.connection == null) {
/* 171 */       this.plugin.logger.info("[KitBattle] Couldn't save the player " + p.getName() + " stats because the connection is null!");
/*     */       
/*     */       return;
/*     */     } 
/* 175 */     if (this.myKits.getContents()[0] != null && this.myKits.getContents()[0].getType() != Material.AIR) {
/* 176 */       Kits = ChatColor.stripColor(this.myKits.getContents()[0].getItemMeta().getDisplayName());
/* 177 */       for (int i = 1; i < this.myKits.getSize(); i++) {
/* 178 */         ItemStack item = this.myKits.getItem(i);
/* 179 */         if (item == null)
/* 180 */           break;  Kits = String.valueOf(Kits) + ", " + ChatColor.stripColor(item.getItemMeta().getDisplayName());
/*     */       } 
/*     */     } else {
/* 183 */       Kits = "NO_KITS";
/*     */     } 
/* 185 */     String playerName = this.plugin.target(p);
/*     */     try {
/* 187 */       Statement sql = this.plugin.connection.createStatement();
/* 188 */       if (sql.executeQuery("SELECT * FROM " + this.plugin.config.tableprefix + " WHERE " + this.plugin.playerNamePrefix + " = '" + playerName + "';").next()) {
/* 189 */         this.plugin.connection.prepareStatement("UPDATE " + this.plugin.config.tableprefix + " SET player_uuid='" + p.getUniqueId().toString() + "', player_name='" + p.getName() + "', Coins=" + this.coins + ", Kills=" + this.kills + ", Deaths=" + this.deaths + ", Exp=" + this.dataexp + ", Rank='" + this.rank.getName() + "', Kitunlockers=" + this.kitUnlockers + ", Kits='" + Kits + "' WHERE " + this.plugin.playerNamePrefix + "='" + playerName + "';").executeUpdate();
/*     */       } else {
/* 191 */         sql.executeUpdate("INSERT INTO " + this.plugin.config.tableprefix + " (player_uuid, player_name, Coins, Kills, Deaths, Exp, Rank, Kitunlockers, Kits) VALUES ('" + p.getUniqueId().toString() + "', '" + p.getName() + "', " + this.coins + ", " + this.kills + ", " + this.deaths + ", " + this.dataexp + ", '" + this.rank.getName() + "', " + this.kitUnlockers + ", '" + Kits + "')");
/*     */       } 
/* 193 */       sql.close();
/* 194 */     } catch (SQLException e) {
/* 195 */       e.printStackTrace();
/*     */     } 
/*     */   }
/*     */   
/*     */   public void saveStatsInPlayersFile(Player p) {
/* 200 */     FileConfiguration file = this.plugin.fileManager.getPlayersConfig();
/* 201 */     String playerName = this.plugin.target(p);
/* 202 */     if (this.plugin.config.UUID) {
/* 203 */       file.set("Players." + playerName + ".Name", p.getName());
/*     */     }
/* 205 */     file.set("Players." + playerName + ".Kills", Integer.valueOf(this.kills));
/* 206 */     file.set("Players." + playerName + ".Deaths", Integer.valueOf(this.deaths));
/* 207 */     file.set("Players." + playerName + ".Coins", Integer.valueOf(this.coins));
/* 208 */     file.set("Players." + playerName + ".Kit-Unlockers", Integer.valueOf(this.kitUnlockers));
/* 209 */     file.set("Players." + playerName + ".Exp", Integer.valueOf(this.dataexp));
/* 210 */     file.set("Players." + playerName + ".Rank", this.rank.getName());
/* 211 */     ArrayList<String> kits = new ArrayList<String>(); byte b; int i; ItemStack[] arrayOfItemStack;
/* 212 */     for (i = (arrayOfItemStack = this.myKits.getContents()).length, b = 0; b < i; ) { ItemStack item = arrayOfItemStack[b];
/* 213 */       if (item == null)
/* 214 */         break;  kits.add(ChatColor.stripColor(item.getItemMeta().getDisplayName())); b++; }
/*     */     
/* 216 */     file.set("Players." + playerName + ".Kits", kits);
/* 217 */     this.plugin.fileManager.savePlayersConfig();
/*     */   }
/*     */   
/*     */   public void saveData(Player p, String map) {
/* 221 */     this.joined = true;
/* 222 */     this.items = p.getInventory().getContents();
/* 223 */     this.armor = p.getInventory().getArmorContents();
/* 224 */     this.location = p.getLocation();
/* 225 */     this.health = p.getHealth();
/* 226 */     this.food = p.getFoodLevel();
/* 227 */     this.levels = p.getLevel();
/* 228 */     this.exp = p.getExp();
/* 229 */     this.potions = p.getActivePotionEffects();
/* 230 */     this.mode = p.getGameMode();
/* 231 */     this.flying = p.isFlying();
/* 232 */     this.map = map;
/*     */   }
/*     */   
/*     */   public void restoreData(Player p) {
/* 236 */     p.getInventory().setContents(this.items);
/* 237 */     p.getInventory().setArmorContents(this.armor);
/* 238 */     p.teleport(this.location);
/* 239 */     p.setHealth(this.health);
/* 240 */     p.setFoodLevel(this.food);
/* 241 */     p.setLevel(this.levels);
/* 242 */     p.setExp(this.exp);
/* 243 */     p.addPotionEffects(this.potions);
/* 244 */     p.setGameMode(this.mode);
/* 245 */     if (this.flying) {
/* 246 */       p.setAllowFlight(true);
/* 247 */       p.setFlying(true);
/*     */     } 
/* 249 */     p.setScoreboard(this.plugin.manager.getNewScoreboard());
/* 250 */     destroyData();
/*     */   }
/*     */ 
/*     */   
/* 254 */   public void setMap(String map) { this.map = map; }
/*     */ 
/*     */ 
/*     */   
/* 258 */   public String getMap() { return this.map; }
/*     */ 
/*     */   
/*     */   public void destroyData() {
/* 262 */     this.items = null;
/* 263 */     this.armor = null;
/* 264 */     this.location = null;
/* 265 */     this.health = 0.0D;
/* 266 */     this.food = 0;
/* 267 */     this.levels = 0;
/* 268 */     this.exp = 0.0F;
/* 269 */     this.potions = null;
/* 270 */     this.mode = null;
/* 271 */     this.map = null;
/* 272 */     this.kit = null;
/* 273 */     this.cooldown = 0L;
/*     */   }
/*     */ 
/*     */   
/* 277 */   public void addKills() { this.kills++; }
/*     */ 
/*     */ 
/*     */   
/* 281 */   public void addDeaths() { this.deaths++; }
/*     */ 
/*     */ 
/*     */   
/* 285 */   public int getKills() { return this.kills; }
/*     */ 
/*     */ 
/*     */   
/* 289 */   public int getDeaths() { return this.deaths; }
/*     */ 
/*     */ 
/*     */   
/* 293 */   public Kit getKit() { return this.kit; }
/*     */ 
/*     */ 
/*     */   
/* 297 */   public void setKit(Kit kit) { this.kit = kit; }
/*     */ 
/*     */ 
/*     */   
/* 301 */   public Inventory getMyKits() { return this.myKits; }
/*     */ 
/*     */ 
/*     */   
/* 305 */   public Inventory getShop() { return this.Shop; }
/*     */ 
/*     */ 
/*     */   
/* 309 */   public void addExp(int Exp) { this.dataexp += Exp; }
/*     */ 
/*     */ 
/*     */   
/* 313 */   public int getExp() { return this.dataexp; }
/*     */ 
/*     */ 
/*     */   
/* 317 */   public Rank getRank() { return this.rank; }
/*     */ 
/*     */ 
/*     */   
/* 321 */   public void setRank(Rank rank) { this.rank = rank; }
/*     */ 
/*     */ 
/*     */   
/* 325 */   public Rank getNextRank() { return this.nextRank; }
/*     */ 
/*     */   
/*     */   public void updateNextRank() {
/* 329 */     if (this.rankNumber + 1 >= Rank.orderd.size()) {
/* 330 */       this.nextRank = null;
/*     */     } else {
/* 332 */       this.nextRank = Rank.orderd.get(this.rankNumber + 1);
/*     */     } 
/*     */   }
/*     */   
/*     */   public void updateRankNumber() {
/* 337 */     for (int i = 0; i < Rank.orderd.size(); i++) {
/* 338 */       if (((Rank)Rank.orderd.get(i)).equals(this.rank)) {
/* 339 */         this.rankNumber = i;
/*     */         break;
/*     */       } 
/*     */     } 
/*     */   }
/*     */   
/*     */   public void giveDefaultStats(List<String> ownedKits) {
/* 346 */     this.coins = this.plugin.config.StartingCoins;
/* 347 */     this.kills = 0;
/* 348 */     this.deaths = 0;
/* 349 */     this.kitUnlockers = this.plugin.config.StartingAmountOfKitUnlockers;
/* 350 */     this.dataexp = 0;
/* 351 */     this.rank = Rank.orderd.get(this.rankNumber);
/* 352 */     for (String x : this.plugin.config.defaultKits)
/* 353 */       ownedKits.add(x.toLowerCase()); 
/*     */   }
/*     */ }


/* Location:              C:\Users\韩烨均\Documents\Tencent Files\133280410\FileRecv\KitBattle.jar!\me\wazup\kitbattle\PlayerData.class
 * Java compiler version: 5 (49.0)
 * JD-Core Version:       1.1.2
 */